<?php
set_time_limit(0);
require_once 'Zend/Loader.php';
require_once 'lib/amazon/amazon_api_class.php';
require_once 'class/Blogger.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>โปรแกรมโพส Amazon ลง Blogger version 3</title>
    </head>
    <body>
        <h1>โพส Amazon ด้วย /Asin version 3</h1>
       
        <?php
        if($_POST['hidden']=='Y') {
            $asso       = trim($_POST['asso']);
            $public     = trim($_POST['public']);
            $private    = trim($_POST['private']);
            $asin    = trim($_POST['asin']);
            $bloggID    = trim($_POST['bid']);
            $email      = trim($_POST['email']);
            $pass       = trim($_POST['pass']);

            $obj_amazon = new AmazonProductAPI();
            $obj_amazon->setAssociateTag($asso);
            $obj_amazon->setPublicKey($public);
            $obj_amazon->setPrivateKey($private);

            try {

				$arr_asin = explode(":", $asin);
				$asin = $arr_asin[0];
				$keyword = $arr_asin[1];

				$xml = $obj_amazon->getItemByAsin($asin);
  
                /* Load XML Template Config */
                $config = @simplexml_load_file("template.xml");
                /* Post To Blogger */
                $obj_blogger = new Blogger();
                $param = array();
                $param['title']   = base64_decode($config->title);
                $param['content'] = base64_decode($config->content);
                $param['keyword'] = $keyword;
                $param['blog_id'] = $bloggID;
                $param['email']   = $email;
                $param['password']= $pass;
				$param['tacking_id'] = $asso;

				
                if($obj_blogger->post($param,$xml)) {
                    echo '<div style="color:green">***Success***</div>';
                }
				

            }catch (Exception $e) {
                echo '<div style="color:red">***'.$e->getMessage().'***</div>';
            }
        }
        ?>
        <form action="" method="post">
            <fieldset>
                <input type="hidden" id="hidden" name="hidden" value="Y" />
                <fieldset style="background: #F2F2F2;"><legend><h3>Blogger Config</h3></legend>
                    <table>
                        <tr>
                            <td>Blogger ID :</td>
                            <td><input type="text" id="bid" name="bid" size="30" /></td>
                        </tr>
                        <tr>
                            <td>Email :</td>
                            <td><input type="text" id="email" name="email" size="30" /></td>
                        </tr>
                        <tr>
                            <td>Password :</td>
                            <td><input type="password" id="pass" name="pass" size="30" /></td>
                        </tr>
                    </table>
                </fieldset>
                <fieldset style="background: #F2F2F2;"><legend><h3>Amazon Config</h3></legend>
                    <table>
                        <tr>
                            <td>Associate Tag :</td>
                            <td><input type="text" id="asso" name="asso" size="50" /></td>
                        </tr>
                        <tr>
                            <td>Public Key :</td>
                            <td><input type="text" id="public" name="public" size="50" /></td>
                        </tr>
                        <tr>
                            <td>Private Key :</td>
                            <td><input type="text" id="private" name="private" size="50" /></td>
                        </tr>
                        <tr>
                            <td>ASIN :</td>
                            <td>
                                <input type="text" id="asin" name="asin" size="50" />
                                <i>วิธีการใส่ ASIN เช่น  B0002GXZK4:keyword</i>
                            </td>
                        </tr>
                    </table>
                </fieldset><br />
                <input type="submit" value="โพสข้อมูล" />
            </fieldset>
        </form>
        <a href ="template.php">ตั้งค่า Template</a>
    </body>
</html>
